﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Besture.Bll;
using Besture.Common;
using Besture.Common.Definition;
using Besture.Model;
using Besture.Utils;

namespace Besture.UI.Control
{
    public partial class LoginInput : System.Web.UI.UserControl
    {
        public UserModel model = null;
        public UserDac dac = null;
        public string card = Fun.Query("card");
        /// <summary>
        /// 登录后跳转的页面
        /// </summary>
        public string RedirectUrl = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (card=="on")
                {
                    loginByName.Visible = false;
                    loginByCard.Style.Add("display","block");
                }
                else
                {
                    loginByName.Visible = true;
                    loginByCard.Style.Add("display", "none");
                }
            }
        }

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Login_Click(object sender, EventArgs e)
        {

           
            model = new UserModel();
            dac = new UserDac();
            string UserName = loginName.Value;
            string Pwd = loginPwd.Value;
            string cardno = CardNo.Value;
            string carpdw = CardPwd.Value;
            //帐号登录
            if (UserName!="" && Pwd!="")
            {
                //验证码
                //if (loginCode.Value.ToUpper() != Session["CheckCode"] + "")
                //{
                //    Session["CheckCode"] = null;
                //    Page.ClientScript.RegisterStartupScript(GetType(), "alertvalidation", "<script>$('#UserError').show();</script>");
                //    return;
                //}
                model = dac.Login(UserName, Fun.GetMD5(Pwd));
            }
         
            //跳转
            if (model != null)
            {
                Session[Constants.SESSION_WEB_USER_MODEL] = model;
                Response.Redirect(!string.IsNullOrEmpty(RedirectUrl) ? RedirectUrl : "/Index.aspx");
            }
            else
            {
                Fun.Alert(this.Page, "密码与用户名不匹配，请重新输入");
            }

        }
    }
}